home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / syslog.c < prev    next >
C/C++ Source or Header  |  1994-09-30  |  6KB  |  187 lines

  1. RCS_ID_C="$Id: syslog.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      syslog.c - syslog function stubs for the AmiTCP/IP
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/param.h>
  11. #include <sys/syslog.h>
  12.  
  13. #include <bsdsocket.h>
  14. #include <amitcp/socketbasetags.h>
  15.  
  16. /****** net.lib/syslog *********************************************
  17. *
  18. *   NAME   
  19. *       openlog(), closelog(), setlogmask() -- syslog utility functions
  20. *
  21. *   SYNOPSIS
  22. *       #include <syslog.h>
  23. *       
  24. *       openlog(ident, logopt, facility);
  25. *
  26. *       void openlog(const char *, int, int);
  27. *
  28. *       closelog();
  29. *
  30. *       void closelog(void);
  31. *
  32. *       oldmask = setlogmask(maskpri);
  33. *       
  34. *       int setlogmask(int);
  35. *       
  36. *   FUNCTION
  37. *       openlog() can be called to initialize the log file, if special
  38. *       processing is needed.  ident is a string that precedes every
  39. *       message.  logopt is a mask of bits, logically OR'ed together,
  40. *       indicating logging options.  The values for logopt are:
  41. *       
  42. *            LOG_PID             Log the process ID with each message;
  43. *                                useful for identifying instantiations
  44. *                                of daemons.
  45. *
  46. *            LOG_CONS            Force writing messages to the console
  47. *                                if unable to send it to syslogd.
  48. *                                This option is safe to use in daemon
  49. *                                processes that have no controlling
  50. *                                terminal because syslog() forks
  51. *                                before opening the console.
  52. *
  53. *            LOG_NDELAY          Open the connection to syslogd
  54. *                                immediately.  Normally, the open is
  55. *                                delayed until the first message is
  56. *                                logged.  This is useful for programs
  57. *                                that need to manage the order in
  58. *                                which file descriptors are allocated.
  59. *
  60. *            LOG_NOWAIT          Do not wait for children forked to
  61. *                                log messages on the console. Obsolete
  62. *                                in AmiTCP/IP, since AmiTCP/IP does
  63. *                                not fork.
  64. *
  65. *       facility encodes a default facility to be assigned to all
  66. *       messages written subsequently by syslog() with no explicit
  67. *       facility encoded. The facility codes are:
  68. *
  69. *            LOG_KERN            Messages generated by the kernel.
  70. *                                These cannot be generated by any user
  71. *                                processes.
  72. *
  73. *            LOG_USER            Messages generated by random user
  74. *                                processes.  This is the default
  75. *                                facility identifier if none is
  76. *                                specified.
  77. *
  78. *            LOG_MAIL            The mail system.
  79. *
  80. *            LOG_DAEMON          System daemons, such as inetd, ftpd,
  81. *                                etc.
  82. *
  83. *            LOG_AUTH            The authorization system: login, su,
  84. *                                getty, etc.
  85. *
  86. *            LOG_LPR             The line printer spooling system: lp,
  87. *                                lpsched, etc.
  88. *
  89. *            LOG_LOCAL0          Reserved for local use. Similarly for
  90. *                                LOG_LOCAL1 through LOG_LOCAL7.
  91. *
  92. *
  93. *       closelog() closes the log file.
  94. *
  95. *       setlogmask() sets the log priority mask to maskpri and returns
  96. *       the previous mask.  Calls to syslog() with a priority not set
  97. *       in maskpri are rejected.  The mask for an individual priority
  98. *       pri is calculated by the macro LOG_MASK(pri); the mask for all
  99. *       priorities up to and including toppri is given by the macro
  100. *       LOG_UPTO(toppri).  By default, all priorities are logged.
  101. *
  102. *   EXAMPLES
  103. *       who logs a message regarding some sort of unexpected and
  104. *       serious error:
  105. *
  106. *           syslog(LOG_ALERT, "who: internal error 23");
  107. *
  108. *       ftpd uses openlog() to arrange to log its process ID, to log
  109. *       to the console if necessary, and to log in the name of the
  110. *       daemon facility:
  111. *
  112. *           openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
  113. *
  114. *       Arrange to log messages only at levels LOG_ERR and lower:
  115. *
  116. *           setlogmask(LOG_UPTO(LOG_ERR));
  117. *
  118. *       Typical usage of syslog() to log a connection:
  119. *
  120. *           syslog(LOG_INFO, "Connection from host %d", CallingHost);
  121. *
  122. *       If the facility has not been set with openlog(), it defaults
  123. *       to LOG_USER.
  124. *
  125. *       Explicitly set the facility for this message:
  126. *
  127. *           syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
  128. *       
  129. *   NOTES
  130. *       openlog() does not copy and store the ident string internally;
  131. *       it stores only the character pointer.  Therefore it is the
  132. *       responsibility of the programmer to make sure that the ident
  133. *       argument points to the correct string while syslog() is being
  134. *       called. 
  135. *
  136. *   BUGS
  137. *       Most of the logopt and facility codes are currently being
  138. *       ignored by AmiTCP/IP, but they should be used for future
  139. *       compatibility.
  140. *
  141. *       The autoinit module of the net.lib tells the program name 
  142. *       to the AmiTCP/IP at program startup, so use of the openlog()
  143. *       for that purpose only is not necessary.
  144. *
  145. *   AUTHOR
  146. *       syslog() was developed by the University of California,
  147. *       Berkeley.
  148. *
  149. *   SEE ALSO
  150. *       bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
  151. *****************************************************************************
  152. *
  153. */
  154. void
  155. openlog(const char *ident, int logstat, int logfac)
  156. {
  157.   /*
  158.    * Note: SocketBaseTags() does value checking for the arguments
  159.    */
  160.   SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR), ident,
  161.          SBTM_SETVAL(SBTC_LOGSTAT), logstat,
  162.          SBTM_SETVAL(SBTC_LOGFACILITY), logfac,
  163.          TAG_END);
  164. }
  165.  
  166. void
  167. closelog(void)
  168. {
  169.   SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR), NULL,
  170.          TAG_END);
  171. }
  172.  
  173. /* setlogmask -- set the log mask level */
  174. int
  175. setlogmask(int pmask)
  176. {
  177.   ULONG taglist[5];
  178.  
  179.   taglist[0] = SBTM_GETVAL(SBTC_LOGMASK);
  180.   taglist[2] = SBTM_SETVAL(SBTC_LOGMASK);
  181.   taglist[3] = pmask;
  182.   taglist[4] = TAG_END;
  183.  
  184.   SocketBaseTagList((struct TagItem *)taglist);
  185.   return (int)taglist[1];
  186. }
  187.